import { MessageBox } from "element-ui";

// 深拷贝
export function deepClone(obj) {
  let output = null;
  if (typeof obj !== "object" || obj === null) {
    return obj;
  }
  if (obj instanceof Array) {
    output = [];
    for (let i = 0; i < obj.length; i++) {
      output[i] = deepClone(obj[i]);
    }
  } else {
    output = {};
    for (let key in obj) {
      if (Object.prototype.hasOwnProperty.call(obj, key)) {
        output[key] = deepClone(obj[key]);
      }
    }
  }
  return output;
}

// table删除的对话框，传入确认后的回调,如果是异步需要改成 async..await的同步形式
export function confirmHandler(cb) {
  MessageBox.confirm("是否确认删除?", "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning"
  })
    .then(cb)
    .catch(() => {});
}
